// 平台属性管理模块的请求文件
import request from '@/utils/request'

const prefix = '/list-api'

// 获取spu列表数据的接口  GET /admin/product/{page}/{limit}   page|limit|category3Id
export const reqSpuList = (page, limit, category3Id) => request({ url: prefix + `/admin/product/${page}/${limit}`, method: 'get', params: { category3Id }})
// export const reqSpuList = (page, limit, category3Id) => request({ url: prefix + `/admin/product/${page}/${limit}?category3Id=${category3Id}`, method: 'get'})

// 获取spu信息    GET /admin/product/getSpuById/{spuId}
export const reqSpu = (spuId) => request({ url: prefix + `/admin/product/getSpuById/${spuId}`, method: 'get' })

// 获取品牌的信息    GET /admin/product/baseTrademark/getTrademarkList
export const reqTradeMarkList = () => request({ url: prefix + '/admin/product/baseTrademark/getTrademarkList', method: 'get' })

// 获取spu图片的接口   GET /admin/product/spuImageList/{spuId}
export const reqSpuImageList = (spuId) => request({ url: prefix + `/admin/product/spuImageList/${spuId}`, method: 'get' })

// 获取平台中所有的销售属性---整个平台销售属性一共三个   GET /admin/product/baseSaleAttrList
export const reqBaseSaleAttrList = () => request({ url: prefix + '/admin/product/baseSaleAttrList', method: 'get' })

// 修改SPU或者添加SPU：对于修改和添加。携带给服务器的参数大致是一样的，唯一区别就是携带参数是否有id
export const reqAddOrUpdateSpu = (spuInfo) => {
  // 携带参数存在id---修改spu
  if (spuInfo.id) {
    return request({ url: prefix + '/admin/product/updateSpuInfo', method: 'post', data: spuInfo })
  } else {
    // 不携带参数id---新增spu
    return request({ url: prefix + '/admin/product/saveSpuInfo', method: 'post', data: spuInfo })
  }
}

// 删除SPU按钮  DELETE /admin/product/deleteSpu/{spuId}
export const reqDeleteSpu = (spuId) => request({ url: prefix + `/admin/product/deleteSpu/${spuId}`, method: 'delete' })

// ---------------------------------------------------------------------

// // 获取spu图片的接口   GET /admin/product/spuImageList/{spuId}
// export const reqSpuImageList = (spuId) => request({ url: prefix + `/admin/product/spuImageList/${spuId}`, method: 'get' })

// 获取销售属性的数据  GET /admin/product/spuSaleAttrList/{spuId}
export const reqSaleAttrList = (spuId) => request({ url: prefix + `/admin/product/spuSaleAttrList/${spuId}`, method: 'get' })

// 获取平台属性的列表数据  GET /admin/product/attrInfoList/{category1Id}/{category2Id}/{category3Id}
export const reqAttrInfoList = (category1Id, category2Id, category3Id) => request({ url: prefix + `/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`, method: 'get' })

// --------------------------------------------------------------------------------

// 添加SKU      POST /admin/product/saveSkuInfo
export const reqAddSku = (skuInfo) => request({ url: prefix + `/admin/product/saveSkuInfo`, method: 'post', data: skuInfo })

// 获取SPU列表数据的接口  GET /admin/product/findBySpuId/{spuId}
export const reqSkuList = (spuId) => request({ url: prefix + `/admin/product/findBySpuId/${spuId}`, method: 'get' })

